package com.jae.service.impl;


import com.jae.mapper.RoleRescMapper;
import com.jae.model.roleResc.RoleResc;
import com.jae.model.roleResc.RoleRescDTO;
import com.jae.model.user.User;
import com.jae.service.RoleRescService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class RoleRescServiceImpl extends BaseServiceImpl implements RoleRescService {

	@Autowired
	private RoleRescMapper roleRescMapper;
	

	/**
	* 	获取所有角色权限	
	*/
	@Override
	public List<RoleRescDTO> findAll(Map map) {
		return roleRescMapper.findAll(map);
	}
	
	/**
	* 	获取一条角色权限	
	*/
	@Override
	public RoleRescDTO findOne(Map map) {
		return roleRescMapper.findOne(map);
	}
	
	/**
	* 	根据ID获取角色权限	
	*/
	@Override
	public RoleRescDTO findById(Integer role_id) {
		RoleResc roleResc = new RoleResc();
		roleResc.setRole_id(role_id);
	
		return roleRescMapper.findById(roleResc);
	}
	
	
	
	/**
	 * 新增角色权限
	 */
	@Override
	public boolean insert(RoleResc roleResc, User user){
		if(roleRescMapper.insert(roleResc)!=1)
			serviceError("插入失败");
		return true;
	}
	
	/**
	 * 修改角色权限
	 */
	@Override
	public boolean update(RoleResc roleResc, User user){
		if(roleRescMapper.update(roleResc)!=1)
			serviceError("修改失败");
		return true;
	}
	
	
	/**
	 * 	逻辑删除角色权限
	 */
	@Override
	public boolean updateDelete(Integer role_id, User user){
		RoleResc old=new RoleResc();
		//roleResc.setLast_updated_by(user.getUser_id());
		//roleResc.setLast_updated_date(new Date());
		old.setRole_id(role_id);
		
		if(roleRescMapper.updateDelete(old)!=1)
			serviceError("逻辑删除失败");
		return true;
	}
	
	/**
	 * 	物理删除角色权限
	 */
	@Override
	public boolean delete(Integer role_id){
		RoleResc old = new RoleResc();
		old.setRole_id(role_id);
		if(roleRescMapper.delete(old)!=1)
			serviceError("删除失败");
		return true;
	}
	
}